import dayjs from 'dayjs'
export default function (app) {
    app.directive('time', {
        mounted(el, bindings) {
            let formatString = bindings.value
            if (!formatString)
                formatString = 'YYYY-MM-DD HH:mm:ss'
            // HH:mm:ss  24小时，hh:mm:ss 12小时
            // YYYY/MM/DD

            const textContent = el.textContent // js获取文本内容
            let timestamp = parseInt(textContent) // 转成数字类型
            if (textContent.length === 10)
                timestamp = timestamp * 1000

            el.textContent = dayjs(timestamp).format(formatString)
        },
    })
}
